<template>
    <Header />
    <StatisticsSearch class="search_box" :options="statisOptions" @submit="onSubmit" />

    <Statistics :chart-data="chartData" />
</template>

<script setup lang="ts">
import Header from './components/Header.vue';
import Statistics from './components/Statistics.vue';
import { getSignTrend, getSignBaseInfo } from '@/api/smartMarketing/signIn';
import StatisticsSearch from '@/components/zw/statistics-search/StatisticsSearch.vue';
import { useRoute } from 'vue-router';
import { ref, reactive, nextTick } from 'vue';
const route = useRoute();

const chartData = ref<any>({
    time: [],
    data: []
});
const statisOptions = reactive([
    {
        label: '时间筛选',
        type: 'dateFilter'
    }
]);
const onSubmit = (data: any) => {
    nextTick(() => {
        const p = {
            activity_id: route.query.id,
            filter_time: data.times || []
        };
        if (data.times) {
            getData(p);
        }
    });
};
const getData = (v: any) => {
    chartData.value = {
        time: [],
        data: []
    };
    getSignTrend(v).then((res: any) => {
        res.forEach((item: any) => {
            chartData.value.time.push(item.sign_time);
            chartData.value.data.push(item.data);
        });
    });
};
</script>

<style scoped lang="scss">
.search_box {
    margin: 16px 0;
}
</style>
